Malaysia Covid19 Case Updates

Prepared By: Zahiruddin Zahidanishah

In [1]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import plotly.graph_objects as go
import plotly.express as px
from plotly.subplots import make_subplots
import dataframe_image as dfi
import adjustText as aT
from jupyterthemes import jtplot
#import requests
import cufflinks as cf
#from bs4 import BeautifulSoup as bs
jtplot.style(theme='monokai', context='notebook', ticks=True, grid=False) 
import warnings
warnings.filterwarnings('ignore')
%matplotlib inline

from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot 
init_notebook_mode(connected=True)
cf.go_offline()

from IPython.display import display_html
def display_side_by_side(*args):
    html_str=''
    for df in args:
        html_str+=df.to_html()
    display_html(html_str.replace('table','table style="display:inline"'),raw=True)
In [2]:
#Covid19 Malaysia States Dataset from MOH, Malaysia Github accounts 
df_states_cases = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/cases_state.csv')
df_states_deaths = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/deaths_state.csv')
df_states_hosp = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/hospital.csv')
df_states_icu = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/icu.csv')
df_states_pkrc = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/pkrc.csv')
df_states_test = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/tests_state.csv')
df_states_vaksin = pd.read_csv('https://raw.githubusercontent.com/CITF-Malaysia/citf-public/main/vaccination/vax_state.csv')
df_states_pop = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/static/population.csv')
In [3]:
df_hosp_daily = df_states_hosp.groupby('date').sum().reset_index()
df_hosp_daily['admitted_covid_cum'] = df_hosp_daily['admitted_covid'].cumsum()
df_hosp_daily['discharged_covid_cum'] = df_hosp_daily['discharged_covid'].cumsum()
df_icu_daily = df_states_icu.groupby('date').sum().reset_index()
df_icu_daily['icu_covid_cum'] = df_icu_daily['icu_covid'].cumsum()
df_pkrc_daily = df_states_pkrc.groupby('date').sum().reset_index()
df_pkrc_daily['admitted_covid_cum'] = df_pkrc_daily['admitted_covid'].cumsum()
df_pkrc_daily['discharged_covid_cum'] = df_pkrc_daily['discharged_covid'].cumsum()
In [4]:
#Selecting the required columns
df_states_cases = df_states_cases[['date','state','cases_new','cases_recovered','cases_pvax','cases_fvax']]
df_date_start = df_states_cases.head(1)
df_date_end = df_states_cases.tail(1)
df_states_deaths = df_states_deaths[['date','state','deaths_new_dod','deaths_bid_dod','deaths_pvax','deaths_fvax']]
df_states_hosp = df_states_hosp[['date','state','admitted_covid','discharged_covid']]
df_states_vaksin = df_states_vaksin[['date','state','daily_partial','daily_full','daily_booster','daily']]
df_states_pop = df_states_pop[['state','pop']]
In [5]:
#Grouping and summation the detasets based on states columns
df_cases = df_states_cases.groupby('state').sum()
df_deaths = df_states_deaths.groupby('state').sum()
df_hosp = df_states_hosp.groupby('state').sum()
df_vaksin = df_states_vaksin.groupby('state').sum()
In [6]:
#Merging the datasets into one datasets
df_states = pd.merge(df_cases,df_deaths,on='state')
In [7]:
df_states = pd.merge(df_states,df_hosp,on='state')
In [8]:
df_states = pd.merge(df_states,df_vaksin,on='state')
In [9]:
df_states = pd.merge(df_states,df_states_pop,on='state')
In [10]:
#Creating main tables for presentation
df_states_table = df_states
df_states_table['deaths_vax_total'] = df_states_table['deaths_pvax'] + df_states_table['deaths_fvax']
df_states_table['cases_vax_total'] = df_states_table['cases_pvax'] + df_states_table['cases_fvax']

df_states_table = df_states_table[['state','cases_new','cases_recovered','cases_vax_total','deaths_new_dod',
                                  'deaths_bid_dod','deaths_vax_total','daily_partial','daily_full','daily',
                                   'daily_booster','pop']]

df_states_table.loc['Total'] = df_states_table.sum(numeric_only=True, axis=0)
df_states_table['state'] = df_states_table['state'].replace(np.nan, 'Malaysia')

df_states_table['Cases (%)'] = df_states_table['cases_new']/df_states_table['pop']*100
df_states_table['Cases Recovered (%)'] = df_states_table['cases_recovered']/df_states_table['cases_new']*100
df_states_table['Cases Vax. (%)'] = df_states_table['cases_vax_total']/df_states_table['cases_new']*100
df_states_table['Deaths (%)'] = df_states_table['deaths_new_dod']/df_states_table['cases_new']*100
df_states_table['Deaths Vax. (%)'] = df_states_table['deaths_vax_total']/df_states_table['deaths_new_dod']*100
df_states_table['Deaths BID (%)'] = df_states_table['deaths_bid_dod']/df_states_table['deaths_new_dod']*100
df_states_table['Vax. 3D (%)'] = df_states_table['daily_booster']/df_states_table['pop']*100
df_states_table['Vax. 2D (%)'] = df_states_table['daily_full']/df_states_table['pop']*100
df_states_table['Vax. 1D (%)'] = df_states_table['daily_partial']/df_states_table['pop']*100

df_states_table.rename(columns={'state':'States','cases_new':'Cases Positive','cases_recovered':'Cases Recovered',
                               'cases_vax_total':'Cases Vax.','deaths_new_dod':'Death Cases',
                               'deaths_bid_dod':'Death BID','deaths_vax_total':'Deaths Vax.',
                               },inplace=True)#'daily':'Total Vaccinated','pop':'Population'
In [11]:
#Creating the main key points from the datasets
print('Key Points Highlights:-')
print('-----------------------------------------------------------------')
print('Report Start Date                        :', df_date_start.at[df_date_start.index[0],'date'])
print('Report End Date                          :', df_date_end.at[df_date_end.index[0],'date'])
print('1. Total Positive Cases                  :','{0:,.0f}'.format(df_states_table.at[df_states_table.index[16],'Cases Positive']),'/','{0:.1f}'.format(df_states_table.at[df_states_table.index[16],'Cases (%)']),'%')
print('2. Total Positive Cases After Vaccinated :','{0:,.0f}'.format(df_states_table.at[df_states_table.index[16],'Cases Vax.']),'/','{0:.1f}'.format(df_states_table.at[df_states_table.index[16],'Cases Vax. (%)']),'%')
print('3. Total Recovered Cases                 :','{0:,.0f}'.format(df_states_table.at[df_states_table.index[16],'Cases Recovered']),'/','{0:.1f}'.format(df_states_table.at[df_states_table.index[16],'Cases Recovered (%)']),'%')
print('4. Total Death Cases                     :','{0:,.0f}'.format(df_states_table.at[df_states_table.index[16],'Death Cases']),'/','{0:.1f}'.format(df_states_table.at[df_states_table.index[16],'Deaths (%)']),'%')
print('5. Total Death Cases After Vaccinated    :','{0:,.0f}'.format(df_states_table.at[df_states_table.index[16],'Deaths Vax.']),'/','{0:.1f}'.format(df_states_table.at[df_states_table.index[16],'Deaths Vax. (%)']),'%')
print('6. Total 1 Dose Vaccinated               :','{0:,.0f}'.format(df_states_table.at[df_states_table.index[16],'daily_partial']),'/','{0:.1f}'.format(df_states_table.at[df_states_table.index[16],'Vax. 1D (%)']),'%')
print('7. Total 2 Dose Vaccinated               :','{0:,.0f}'.format(df_states_table.at[df_states_table.index[16],'daily_full']),'/','{0:.1f}'.format(df_states_table.at[df_states_table.index[16],'Vax. 2D (%)']),'%')
print('8. Total 3 Dose Vaccinated               :','{0:,.0f}'.format(df_states_table.at[df_states_table.index[16],'daily_booster']),'/','{0:.1f}'.format(df_states_table.at[df_states_table.index[16],'Vax. 3D (%)']),'%')
print('-----------------------------------------------------------------')
Key Points Highlights:-
-----------------------------------------------------------------
Report Start Date                        : 2020-01-25
Report End Date                          : 2022-02-12
1. Total Positive Cases                  : 3,019,163 / 9.2 %
2. Total Positive Cases After Vaccinated : 1,195,868 / 39.6 %
3. Total Recovered Cases                 : 2,846,713 / 94.3 %
4. Total Death Cases                     : 32,114 / 1.1 %
5. Total Death Cases After Vaccinated    : 11,096 / 34.6 %
6. Total 1 Dose Vaccinated               : 26,016,068 / 79.7 %
7. Total 2 Dose Vaccinated               : 25,731,438 / 78.8 %
8. Total 3 Dose Vaccinated               : 13,174,229 / 40.3 %
-----------------------------------------------------------------
In [12]:
df_states_table.drop(['daily_partial','daily_full','pop','daily','daily_booster'],axis='columns',inplace=True)
In [13]:
df_states_table.drop(['Cases Vax.','Death BID','Deaths Vax.'],axis='columns',inplace=True)

df_states_table.style.set_caption("Malaysia Details Of Covid19 Cases At Each States").set_table_styles([{
    'selector': 'caption',
    'props': [
        ('color', 'black'),
        ('font-size', '26px'),
        ("text-align", "center"),
        ('text-decoration', 'underline'),
        ('font-family','Arial'),
        ('text-shadow', '2px 2px 5px grey')
    ]},(dict
        (selector='th',props=[('text-align',
                               'left')]))]).format(
    {'Cases Positive':'{:,.0f}','Cases Recovered':'{:,.0f}','Cases Vax.':'{:,.0f}','Death Cases':'{:,.0f}',
     'Deaths (%)':'{:,.1f}','Deaths BID':'{:,.0f}','Deaths Vax.':'{:,.0f}','Cases (%)':'{:,.1f}',
     'Cases Recovered (%)':'{:,.1f}','Cases Vax. (%)':'{:,.1f}','Vax. 2D (%)':'{:,.1f}','Vax. 1D (%)':'{:,.1f}',
     'Deaths Vax. (%)':'{:,.1f}','Deaths BID (%)':'{:,.1f}','Vax. 3D (%)':'{:,.1f}'}
).set_properties(subset=['States'],**{'text-align': 'left'}).apply(
    lambda x: ['background: salmon' if x.name in ['Total'] else '' for i in x], axis=1).hide_index()
Out[13]:
Malaysia Details Of Covid19 Cases At Each States
States Cases Positive Cases Recovered Death Cases Cases (%) Cases Recovered (%) Cases Vax. (%) Deaths (%) Deaths Vax. (%) Deaths BID (%) Vax. 3D (%) Vax. 2D (%) Vax. 1D (%)
Johor 280,008 256,592 3,939 7.4 91.6 37.6 1.4 37.4 12.8 42.7 80.5 81.2
Kedah 191,291 177,520 2,199 8.7 92.8 39.4 1.1 32.7 15.0 28.2 72.0 72.6
Kelantan 188,271 178,029 1,286 9.8 94.6 44.1 0.7 34.6 22.9 13.4 61.2 61.9
Melaka 87,207 82,133 977 9.3 94.2 37.1 1.1 36.9 13.1 49.9 76.6 77.9
Negeri Sembilan 125,650 118,348 1,342 11.1 94.2 29.6 1.1 28.8 11.1 47.9 84.3 85.2
Pahang 108,876 101,483 814 6.5 93.2 42.7 0.7 34.4 12.7 30.7 70.0 70.3
Perak 137,041 132,195 1,461 5.5 96.5 39.6 1.1 43.4 13.2 35.7 74.3 74.8
Perlis 8,653 7,513 139 3.4 86.8 57.4 1.6 45.3 5.0 22.5 80.2 80.9
Pulau Pinang 177,451 168,029 1,775 10.0 94.7 43.4 1.0 40.0 21.2 49.9 86.1 86.6
Sabah 270,369 243,628 2,846 7.1 90.1 37.4 1.1 23.8 39.1 14.3 62.6 60.9
Sarawak 254,026 251,321 1,622 9.0 98.9 54.2 0.6 49.0 20.8 52.1 75.7 78.2
Selangor 850,216 806,715 10,073 13.0 94.9 36.5 1.2 32.6 21.2 51.0 73.1 74.7
Terengganu 87,818 84,388 764 6.9 96.1 45.8 0.9 41.5 11.1 23.3 69.2 69.9
W.P. Kuala Lumpur 229,106 217,732 2,704 13.1 95.0 36.2 1.2 34.4 25.7 88.5 173.6 176.5
W.P. Labuan 11,585 10,917 151 11.6 94.2 19.6 1.3 9.3 28.5 41.3 79.8 83.2
W.P. Putrajaya 11,595 10,170 22 10.0 87.7 44.5 0.2 31.8 4.5 59.7 127.0 129.7
Malaysia 3,019,163 2,846,713 32,114 9.2 94.3 39.6 1.1 34.6 20.2 40.3 78.8 79.7
In [14]:
df_states_graph = df_states
df_states_graph['vaksin_percentage_partial'] = df_states_graph['daily_partial']/df_states_graph['pop']*100
df_states_graph['vaksin_percentage_full'] = df_states_graph['daily_full']/df_states_graph['pop']*100
df_states_graph['deaths_vax_total'] = df_states_graph['deaths_pvax'] + df_states_graph['deaths_fvax']
df_states_graph['cases_vax_total'] = df_states_graph['cases_pvax'] + df_states_graph['cases_fvax']
In [15]:
#Dataset for overall Malaysia Covid19
df_mas_cases = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/cases_malaysia.csv')
df_mas_deaths = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/deaths_malaysia.csv')
df_mas_test = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/tests_malaysia.csv')
df_mas_vaksin = pd.read_csv('https://raw.githubusercontent.com/CITF-Malaysia/citf-public/main/vaccination/vax_malaysia.csv')
df_mas_pop = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/static/population.csv')
df_mas_aefi = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/vaccination/aefi.csv')
In [16]:
df_mas_vaksin['Total Pfizer'] = df_mas_vaksin['pfizer1'] + df_mas_vaksin['pfizer2']
df_mas_vaksin['Total Sinovac'] = df_mas_vaksin['sinovac1'] + df_mas_vaksin['sinovac2']
df_mas_vaksin['Total AstraZ'] = df_mas_vaksin['astra1'] + df_mas_vaksin['astra2']
df_mas_vaksin['Cum. Daily'] = df_mas_vaksin['daily_full'].cumsum()
df_mas_vaksin['Population'] = df_states_pop.at[df_states_pop.index[0],'pop']
df_mas_vaksin['Vax. (%)'] = (df_mas_vaksin['Cum. Daily']/df_mas_vaksin['Population'])*100
In [17]:
df_mas_cases = df_mas_cases[['date','cases_new','cases_recovered','cases_pvax','cases_fvax']]
df_mas_deaths = df_mas_deaths[['date','deaths_new_dod','deaths_bid_dod','deaths_pvax','deaths_fvax']]
df_mas_vaksin = df_mas_vaksin[['date', 'daily_partial', 'daily_full', 'daily_booster', 'daily', 'Total Pfizer',
                               'Total Sinovac', 'Total AstraZ', 'cansino', 'Cum. Daily', 'Vax. (%)']]
In [18]:
df_mas = pd.merge(df_mas_cases, df_mas_deaths, on='date')
In [19]:
df_mas = pd.merge(df_mas, df_mas_vaksin, on='date')
In [20]:
df_mas_deaths['deaths_vax_total'] = df_mas_deaths['deaths_pvax'] + df_mas_deaths['deaths_fvax']
df_mas['deaths_vax_total'] = df_mas['deaths_pvax'] + df_mas['deaths_fvax']
df_mas_test['total_test'] = df_mas_test['rtk-ag'] + df_mas_test['pcr']
df_mas_test['cum_total'] = df_mas_test['total_test'].cumsum()
In [21]:
df_mas_new = df_mas[['date','cases_new','deaths_new_dod']]
df_mas_new['cases_new_7'] = df_mas_new['cases_new'].shift(7)
df_mas_new['cases_new_14'] = df_mas_new['cases_new'].shift(14)
df_mas_new['cases_new_21'] = df_mas_new['cases_new'].shift(21)
df_mas_new['deaths_new_7'] = df_mas_new['deaths_new_dod'].shift(7)
df_mas_new['deaths_new_14'] = df_mas_new['deaths_new_dod'].shift(14)
df_mas_new['deaths_new_21'] = df_mas_new['deaths_new_dod'].shift(21)
df_mas_new = df_mas_new.tail(7)
df_mas_new['cum_new'] = df_mas_new['cases_new'].cumsum()
df_mas_new['cum_new_7'] = df_mas_new['cases_new_7'].cumsum()
df_mas_new['cum_new_14'] = df_mas_new['cases_new_14'].cumsum()
df_mas_new['cum_new_21'] = df_mas_new['cases_new_21'].cumsum()
df_mas_new['cum_deaths_new'] = df_mas_new['deaths_new_dod'].cumsum()
df_mas_new['cum_deaths_7'] = df_mas_new['deaths_new_7'].cumsum()
df_mas_new['cum_deaths_14'] = df_mas_new['deaths_new_14'].cumsum()
df_mas_new['cum_deaths_21'] = df_mas_new['deaths_new_21'].cumsum()
In [22]:
print('Four Weeks Cumulative Daily Cases Comparison Analysis:-')
print('--------------------------------------------')
print('Average Week 1: ', '{0:,.0f}'.format(df_mas_new['cum_new'].mean()), '(', '{0:,.0f}'.format(df_mas_new['cum_new'].mean()-df_mas_new['cum_new_7'].mean()),'diff.)')
print('Average Week 2: ', '{0:,.0f}'.format(df_mas_new['cum_new_7'].mean()), '(', '{0:,.0f}'.format(df_mas_new['cum_new_7'].mean()-df_mas_new['cum_new_14'].mean()),'diff.)')
print('Average Week 3: ', '{0:,.0f}'.format(df_mas_new['cum_new_14'].mean()), '(', '{0:,.0f}'.format(df_mas_new['cum_new_14'].mean()-df_mas_new['cum_new_21'].mean()),'diff.)')
print('Average Week 4: ', '{0:,.0f}'.format(df_mas_new['cum_new_21'].mean()), '-')
print('--------------------------------------------')
print('Four Weeks Daily Cases Comparison Analysis:-')
print('--------------------------------------------')
print('Average Week 1:', '{0:,.0f}'.format(df_mas_new['cases_new'].mean()), '(', '{0:,.0f}'.format(df_mas_new['cases_new'].mean()-df_mas_new['cases_new_7'].mean()),'diff.)')
print('Average Week 2:', '{0:,.0f}'.format(df_mas_new['cases_new_7'].mean()), '(', '{0:,.0f}'.format(df_mas_new['cases_new_7'].mean()-df_mas_new['cases_new_14'].mean()),'diff.)')
print('Average Week 3:', '{0:,.0f}'.format(df_mas_new['cases_new_14'].mean()), '(', '{0:,.0f}'.format(df_mas_new['cases_new_14'].mean()-df_mas_new['cases_new_21'].mean()),'diff.)')
print('Average Week 4:', '{0:,.0f}'.format(df_mas_new['cases_new_21'].mean()), '-')
print('--------------------------------------------')
Four Weeks Cumulative Daily Cases Comparison Analysis:-
--------------------------------------------
Average Week 1:  56,719 ( 34,638 diff.)
Average Week 2:  22,081 ( 5,212 diff.)
Average Week 3:  16,869 ( 4,331 diff.)
Average Week 4:  12,538 -
--------------------------------------------
Four Weeks Daily Cases Comparison Analysis:-
--------------------------------------------
Average Week 1: 16,433 ( 10,281 diff.)
Average Week 2: 6,152 ( 1,583 diff.)
Average Week 3: 4,569 ( 1,175 diff.)
Average Week 4: 3,393 -
--------------------------------------------
In [23]:
fig = make_subplots(rows=1, cols=4, shared_xaxes=True, vertical_spacing=0.08,
                   subplot_titles=('<b>New Confirmed Cases Daily</b>',
                                   '<b>New Confirmed Cases Cumulative</b>',
                                   '<b>New Deaths Cases Daily</b>',
                                   '<b>New Deaths Cases Cumulative</b>'))
#Graph 1
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cases_new'],name='Week 1', mode="lines",
                           line = dict(color='red',width=0.5)),row=1, col=1)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cases_new_7'],name='Week 2', mode="lines",
                           line = dict(color='blue',width=0.5)),row=1, col=1)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cases_new_14'],name='Week 3', mode="lines",
                           line = dict(color='green',width=0.5)),row=1, col=1)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cases_new_21'],name='Week 4', mode="lines",
                           line = dict(color='purple',width=0.5)),row=1, col=1)
fig.add_hline(y=df_mas_new['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Ave. Week 1", annotation_position="bottom left",row=1, col=1)
fig.add_hline(y=df_mas_new['cases_new_7'].mean(), line_dash="dot",line_color="blue",
              annotation_text="Ave. Week 2", annotation_position="bottom right",row=1, col=1)
fig.add_hline(y=df_mas_new['cases_new_14'].mean(), line_dash="dot",line_color="green",
              annotation_text="Ave. Week 3", annotation_position="bottom left",row=1, col=1)
fig.add_hline(y=df_mas_new['cases_new_21'].mean(), line_dash="dot",line_color="purple",
              annotation_text="Ave. Week 4", annotation_position="bottom right",row=1, col=1)
#Graph 2
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cum_new'],name='Week 1', mode="lines",
                           line = dict(color='red',width=0.5)),row=1, col=2)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cum_new_7'],name='Week 2', mode="lines",
                           line = dict(color='blue',width=0.5)),row=1, col=2)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cum_new_14'],name='Week 3', mode="lines",
                           line = dict(color='green',width=0.5)),row=1, col=2)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cum_new_21'],name='Week 4', mode="lines",
                           line = dict(color='purple',width=0.5)),row=1, col=2)
fig.add_hline(y=df_mas_new['cum_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Ave. Week 1", annotation_position="bottom left",row=1, col=2)
fig.add_hline(y=df_mas_new['cum_new_7'].mean(), line_dash="dot",line_color="blue",
              annotation_text="Ave. Week 2", annotation_position="bottom right",row=1, col=2)
fig.add_hline(y=df_mas_new['cum_new_14'].mean(), line_dash="dot",line_color="green",
              annotation_text="Ave. Week 3", annotation_position="top left",row=1, col=2)
fig.add_hline(y=df_mas_new['cum_new_21'].mean(), line_dash="dot",line_color="purple",
              annotation_text="Ave. Week 4", annotation_position="bottom right",row=1, col=2)
#Graph 3
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['deaths_new_dod'],name='Week 1', mode="lines",
                           line = dict(color='red', width=0.5)),row=1, col=3)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['deaths_new_7'],name='Week 2', mode="lines",
                           line = dict(color='blue', width=0.5)),row=1, col=3)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['deaths_new_14'],name='Week 3', mode="lines",
                           line = dict(color='green', width=0.5)),row=1, col=3)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['deaths_new_21'],name='Week 4', mode="lines",
                           line = dict(color='purple', width=0.5)),row=1, col=3)
fig.add_hline(y=df_mas_new['deaths_new_dod'].mean(), line_dash="dot",line_color="red",
              annotation_text="Ave. Week 1", annotation_position="bottom left",row=1, col=3)
fig.add_hline(y=df_mas_new['deaths_new_7'].mean(), line_dash="dot",line_color="blue",
              annotation_text="Ave. Week 2", annotation_position="bottom right",row=1, col=3)
fig.add_hline(y=df_mas_new['deaths_new_14'].mean(), line_dash="dot",line_color="green",
              annotation_text="Ave. Week 3", annotation_position="bottom left",row=1, col=3)
fig.add_hline(y=df_mas_new['deaths_new_21'].mean(), line_dash="dot",line_color="purple",
              annotation_text="Ave. Week 4", annotation_position="bottom right",row=1, col=3)
#Graph 4
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cum_deaths_new'],name='Week 1', mode="lines",
                           line = dict(color='red', width=0.5)),row=1, col=4)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cum_deaths_7'],name='Week 2', mode="lines",
                           line = dict(color='blue', width=0.5)),row=1, col=4)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cum_deaths_14'],name='Week 3', mode="lines",
                           line = dict(color='green', width=0.5)),row=1, col=4)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cum_deaths_21'],name='Week 4', mode="lines",
                           line = dict(color='purple', width=0.5)),row=1, col=4)
fig.add_hline(y=df_mas_new['cum_deaths_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Ave. Week 1", annotation_position="bottom left",row=1, col=4)
fig.add_hline(y=df_mas_new['cum_deaths_7'].mean(), line_dash="dot",line_color="blue",
              annotation_text="Ave. Week 2", annotation_position="bottom right",row=1, col=4)
fig.add_hline(y=df_mas_new['cum_deaths_14'].mean(), line_dash="dot",line_color="green",
              annotation_text="Ave. Week 3", annotation_position="bottom left",row=1, col=4)
fig.add_hline(y=df_mas_new['cum_deaths_21'].mean(), line_dash="dot",line_color="purple",
              annotation_text="Ave. Week 4", annotation_position="top right",row=1, col=4)
#Update Fonts & Size
fig.update_annotations(font=dict(family="Helvetica", size=11))
fig.update_layout(font=dict(family="Helvetica", size=11))
fig.update_layout(height=400,showlegend=False,title_text="Malaysia Covid19 Latest Cases In Details (4 Week Comparison)", title_x=0.5)
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black',
                visible=True, showticklabels=False)
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
#Plotting the graph
fig.show()
In [24]:
df_mas_cases['cum_new'] = df_mas_cases['cases_new'].cumsum()
df_mas_cases['cum_recovered'] = df_mas_cases['cases_recovered'].cumsum()
df_mas_deaths['cum_deaths'] = df_mas_deaths['deaths_new_dod'].cumsum()
df_mas_deaths['cum_deaths_vax'] = df_mas_deaths['deaths_vax_total'].cumsum()
In [25]:
fig = make_subplots(rows=2, cols=4, shared_xaxes=True, vertical_spacing=0.08,
                    specs=[[{'secondary_y': True}, {'secondary_y': True}, {'secondary_y': True}, {'secondary_y': True}], 
                           [{'secondary_y': True}, {'secondary_y': True}, {'secondary_y': True}, {'secondary_y': True}]],

subplot_titles=('<b>Cases: Total VS Recover</b>',
                '<b>ICU Daily Admitted</b>',
                '<b>Hosp.: Admit VS Discharge</b>',
                '<b>PKRC: Admitted VS Discharged</b>',
                '<b>Deaths: Total, BID & Vax.</b>',
                '<b>Total Daily Covid19 Test</b>',
                '<b>States Hosp. Admission & Discharge</b>',
                '<b>States Vax. (%): 1D VS 2D</b>'))

#Graph 1
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_cases['cases_new'], name='Positive Cases',
                           line = dict(color='red',width=0.5)), row=1, col=1, secondary_y=True)
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_cases['cum_new'], name='Positive Cases',
                           line = dict(color='red',width=1)), row=1, col=1, secondary_y=False)
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_cases['cases_recovered'],name='Recovered Cases',
                            line = dict(color='blue',width=0.5)),row=1, col=1, secondary_y=True)
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_cases['cum_recovered'],name='Recovered Cases',
                            line = dict(color='blue',width=1)),row=1, col=1, secondary_y=False)
fig.add_hline(y=df_mas_cases['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Ave. Cases", annotation_position="bottom left",row=1, col=1)
fig.add_hline(y=df_mas_cases['cases_recovered'].mean(), line_dash="dot",line_color="blue",
              annotation_text="Ave. Recovered", annotation_position="top left",row=1, col=1)
#Graph 2
fig.add_trace(go.Scatter(x = df_icu_daily['date'], y = df_icu_daily['icu_covid'],name='ICU Covid',
                           line = dict(color='blue', width=0.5)),row=1, col=2, secondary_y=True)
fig.add_trace(go.Scatter(x = df_icu_daily['date'], y = df_icu_daily['icu_covid_cum'],name='ICU Covid',
                           line = dict(color='red', width=0.5)),row=1, col=2, secondary_y=False)
fig.add_hline(y = df_icu_daily['icu_covid'].mean(), line_dash="dot",line_color="blue",
              annotation_text="Ave. Daily", annotation_position="bottom left",row=1, col=2)
fig.add_hline(y = df_icu_daily['icu_covid_cum'].mean(), line_dash="dot",line_color="red",
              annotation_text="Ave. Cum.", annotation_position="bottom left",row=1, col=2)
# Graph 3
fig.add_trace(go.Scatter(x = df_mas_deaths['date'], y = df_mas_deaths['deaths_new_dod'],name='Deaths Cases',
                           line = dict(width=0.5, color='blue')),row=2, col=1, secondary_y=True)
fig.add_trace(go.Scatter(x = df_mas_deaths['date'], y = df_mas_deaths['cum_deaths'],name='Deaths Cases',
                           line = dict(width=1, color='blue')),row=2, col=1, secondary_y=False)
fig.add_hline(y=df_mas_deaths['deaths_new_dod'].mean(), line_dash="dot",line_color="blue",
              annotation_text="Ave. Daily Deaths", annotation_position="top left",row=2, col=1)
fig.add_trace(go.Scatter(x = df_mas_deaths['date'], y = df_mas_deaths['deaths_bid_dod'],name='BID Cases',
                           line = dict(width=0.5, color='red')),row=2, col=1, secondary_y=True)
fig.add_trace(go.Scatter(x = df_mas_deaths['date'], y = df_mas_deaths['deaths_vax_total'],name='Deaths Vaccinated Cases',
                            line = dict(width=0.5, color='black')),row=2, col=1, secondary_y=True)
fig.add_trace(go.Scatter(x = df_mas_deaths['date'], y = df_mas_deaths['cum_deaths_vax'],name='Deaths Vaccinated Cases',
                            line = dict(width=1, color='black')),row=2, col=1, secondary_y=False)
#Graph 4
fig.add_trace(go.Scatter(x = df_mas_test['date'], y = df_mas_test['total_test'],name='Daily Covid19 Test',
                           line = dict(color='blue', width=0.5)),row=2, col=2, secondary_y=False)
fig.add_trace(go.Scatter(x = df_mas_test['date'], y = df_mas_test['cum_total'],name='Cumulative Covid19 Test',
                           line = dict(color='red', width=1)),row=2, col=2, secondary_y=True)
fig.add_hline(y=df_mas_test['total_test'].mean(), line_dash="dot",line_color="blue",
              annotation_text="Ave. Daily Test", annotation_position="top left",row=2, col=2)
#Graph 5
fig.add_trace(go.Scatter(x = df_hosp_daily['date'], y = df_hosp_daily['admitted_covid'],name='Admitted',
                           line = dict(color='blue', width=0.5)),row=1, col=3, secondary_y=True)
fig.add_trace(go.Scatter(x = df_hosp_daily['date'], y = df_hosp_daily['discharged_covid'],name='Discharged',
                           line = dict(color='red', width=0.5)),row=1, col=3, secondary_y=True)
fig.add_trace(go.Scatter(x = df_hosp_daily['date'], y = df_hosp_daily['admitted_covid_cum'],name='Admitted',
                           line = dict(color='blue', width=1)),row=1, col=3, secondary_y=False)
fig.add_trace(go.Scatter(x = df_hosp_daily['date'], y = df_hosp_daily['discharged_covid_cum'],name='Discharged',
                           line = dict(color='red', width=1)),row=1, col=3, secondary_y=False)
fig.add_hline(y = df_hosp_daily['admitted_covid'].mean(), line_dash="dot",line_color="blue",
              annotation_text="Ave. Admitted", annotation_position="bottom left",row=1, col=3)
fig.add_hline(y = df_hosp_daily['discharged_covid'].mean(), line_dash="dot",line_color="red",
              annotation_text="Ave. Discharged", annotation_position="top left",row=1, col=3)
#Graph 6
fig.add_trace(go.Scatter(x = df_pkrc_daily['date'], y = df_pkrc_daily['admitted_covid'],name='Admitted',
                           line = dict(color='blue', width=0.5)),row=1, col=4, secondary_y=True)
fig.add_trace(go.Scatter(x = df_pkrc_daily['date'], y = df_pkrc_daily['discharged_covid'],name='Discharged',
                           line = dict(color='red', width=0.5)),row=1, col=4, secondary_y=True)
fig.add_trace(go.Scatter(x = df_pkrc_daily['date'], y = df_pkrc_daily['admitted_covid_cum'],name='Admitted',
                           line = dict(color='blue', width=1)),row=1, col=4, secondary_y=False)
fig.add_trace(go.Scatter(x = df_pkrc_daily['date'], y = df_pkrc_daily['discharged_covid_cum'],name='Discharged',
                           line = dict(color='red', width=1)),row=1, col=4, secondary_y=False)
fig.add_hline(y = df_pkrc_daily['admitted_covid'].mean(), line_dash="dot",line_color="blue",
              annotation_text="Ave. Admitted", annotation_position="bottom left",row=1, col=4)
fig.add_hline(y = df_pkrc_daily['discharged_covid'].mean(), line_dash="dot",line_color="red",
              annotation_text="Ave. Discharged", annotation_position="top left",row=1, col=4)
#Graph 7
fig.add_trace(go.Bar(x = df_states_graph['state'], y = df_states_graph['admitted_covid'],name='Admitted Cases',
                       marker_color='blue'),row=2, col=3, secondary_y=False)
fig.add_trace(go.Bar(x = df_states_graph['state'], y = df_states_graph['discharged_covid'],name='Discharged Cases',
                       marker_color='red'),row=2, col=3, secondary_y=False)
#Graph 8
fig.add_trace(go.Bar(x = df_states_graph['state'], y = df_states_graph['vaksin_percentage_partial'],
                        name='Partial Vaksin (%)',marker_color='blue'),row=2, col=4, secondary_y=False)
fig.add_trace(go.Bar(x = df_states_graph['state'], y = df_states_graph['vaksin_percentage_full'],
                        name='Full Vaksin (%)',marker_color='red'),row=2, col=4, secondary_y=False)
#Update Fonts & Size
fig.update_annotations(font=dict(family="Helvetica", size=11))
fig.update_layout(font=dict(family="Helvetica", size=11))
fig.update_layout(height=600,showlegend=False,title_text="Malaysia Covid19 Cases Overview", title_x=0.5)
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')

# add a horizontal line & annotations
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0=0, x1=16, xref="paper", y0=90, y1=90, yref="y",row=2, col=4)
fig.add_annotation(text='90% Vax. Pop.', x=6, y=90, arrowhead=1, showarrow=True,row=2, col=4)
#Plotting the graph
fig.show()
In [26]:
df_mas_monthly = df_mas_cases.append(df_mas_deaths)

def getYearMonth(s):
  return s.split("-")[1]+"-"+s.split("-")[0]
df_mas_monthly['YearMonth']= df_mas_monthly['date'].apply(lambda x: getYearMonth(x))

df_mas_monthly = df_mas_monthly.groupby('YearMonth').sum()
df_mas_monthly = df_mas_monthly.reset_index()
df_mas_monthly['vax_total_cases'] = df_mas_monthly['cases_fvax']+df_mas_monthly['cases_pvax']
df_mas_monthly['vax_total_deaths'] = df_mas_monthly['deaths_fvax']+df_mas_monthly['deaths_pvax']
In [27]:
df_mas_yearly = df_mas_cases.append(df_mas_deaths)

def getYear(s):
  return s.split("-")[0]

def getMonth(s):
  return s.split("-")[1]

df_mas_yearly['Year']= df_mas_yearly['date'].apply(lambda x: getYear(x))
df_mas_yearly['Month']= df_mas_yearly['date'].apply(lambda x: getMonth(x))

df_mas_yearly = df_mas_yearly.groupby('Year').sum().reset_index()
df_mas_yearly['vax_total_cases'] = df_mas_yearly['cases_fvax']+df_mas_yearly['cases_pvax']
df_mas_yearly['vax_total_deaths'] = df_mas_yearly['deaths_fvax']+df_mas_yearly['deaths_pvax']
In [28]:
fig = make_subplots(rows=1, cols=2, shared_xaxes=True, vertical_spacing=0.08,
                   subplot_titles=('<b>Yearly Total Covid19 Cases & Recovered</b>',
                                   '<b>Monthly Total Covid19 Cases & Recovered</b>'))
#Graph 1
fig.append_trace(go.Bar(x = df_mas_yearly['Year'], y = df_mas_yearly['cases_new'],
                        name='Cases Positive',marker_color='indianred'),row=1, col=1)
fig.append_trace(go.Bar(x = df_mas_yearly['Year'], y = df_mas_yearly['cases_recovered'],
                        name='Cases Recovered',marker_color='lightsalmon'),row=1, col=1)
#Graph 2
fig.append_trace(go.Bar(x = df_mas_monthly['YearMonth'], y = df_mas_monthly['cases_new'],
                        name='Cases Positive',marker_color='indianred'),row=1, col=2)
fig.append_trace(go.Bar(x = df_mas_monthly['YearMonth'], y = df_mas_monthly['cases_recovered'],
                        name='Cases Recovered',marker_color='lightsalmon'),row=1, col=2)

#Update Fonts & Size
fig.update_annotations(font=dict(family="Helvetica", size=11))
fig.update_layout(font=dict(family="Helvetica", size=11))
fig.update_layout(height=400,showlegend=False,title_text='Yearly and Monthly Total New And Recovered Cases', title_x=0.5)
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')

#Plotting the graph
fig.show()
In [29]:
fig = make_subplots(rows=1, cols=4, specs=[[{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}]],
                    
subplot_titles=('<b>Total Daily Vax.</b>',
                '<b>Cumulative Daily Vax.</b>',
                '<b>Full, Partial & Booster</b>',
                '<b>Pfizer, Sinovac, AZ & Cansino</b>'))
#Graph 1
fig.add_trace(go.Scatter(x = df_mas_vaksin['date'], y = df_mas_vaksin['daily'],name='Total Daily Vaccinated',
                           line = dict(color='red',width=0.5)),row=1, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_mas_vaksin['date'], y = df_mas_vaksin['Vax. (%)'],name='Vax. (%)',
                           line = dict(color='blue',width=0.5)),row=1, col=1,secondary_y=True)
fig.add_hline(y=df_mas_vaksin['daily'].mean(), line_dash="dot",line_color="black",
              annotation_text="Ave. Daily Vax.", annotation_position="top left",row=1, col=1)
#Graph 2
fig.add_trace(go.Scatter(x = df_mas_vaksin['date'], y = df_mas_vaksin['Cum. Daily'],name='Cum. Daily Vaccinated',
                           line = dict(color='red',width=0.5)),row=1, col=2,secondary_y=False)
fig.add_hline(y=df_mas_vaksin['Cum. Daily'].mean(), line_dash="dot",line_color="black",
              annotation_text="Ave. Cum. Vax.", annotation_position="top left",row=1, col=2)
#Grpah 3
fig.add_trace(go.Scatter(x = df_mas_vaksin['date'], y = df_mas_vaksin['daily_partial'],name='Partial',
                           line = dict(color='red',width=0.5)),row=1, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_mas_vaksin['date'], y = df_mas_vaksin['daily_full'],name='Full',
                           line = dict(color='blue',width=0.5)),row=1, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_mas_vaksin['date'], y = df_mas_vaksin['daily_booster'],name='Booster',
                           line = dict(color='green',width=0.5)),row=1, col=3,secondary_y=True)
fig.add_hline(y=df_mas_vaksin['daily'].mean(), line_dash="dot",line_color="black",
              annotation_text="Ave. Daily Vax.", annotation_position="top left",row=1, col=3)
#Graph 4
fig.add_trace(go.Scatter(x = df_mas_vaksin['date'], y = df_mas_vaksin['Total Pfizer'],name='Pfizer',
                           line = dict(color='red',width=0.5)),row=1, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_mas_vaksin['date'], y = df_mas_vaksin['Total Sinovac'],name='Sinovac',
                           line = dict(color='blue',width=0.5)),row=1, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_mas_vaksin['date'], y = df_mas_vaksin['Total AstraZ'],name='Astra Zaneca',
                           line = dict(color='green',width=0.5)),row=1, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_mas_vaksin['date'], y = df_mas_vaksin['cansino'],name='Cansino',
                           line = dict(color='black',width=0.5)),row=1, col=4,secondary_y=True)
fig.add_hline(y=df_mas_vaksin['daily'].mean(), line_dash="dot",line_color="black",
              annotation_text="Ave. Daily Vax.", annotation_position="top left",row=1, col=4)
#Update Fonts & Size
fig.update_annotations(font=dict(family="Helvetica", size=11))
fig.update_layout(font=dict(family="Helvetica", size=11))
fig.update_layout(height=350,showlegend=False,title_text="Daily Vaccination Details", title_x=0.5)
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')

#Plotting the graph
fig.show()
In [30]:
df_mas_cases['total_vax'] = df_mas_cases['cases_pvax'] + df_mas_cases['cases_fvax']
df_mas_cases['cum_new'] = df_mas_cases['cases_new'].cumsum()
df_mas_cases['cum_recovered'] = df_mas_cases['cases_recovered'].cumsum()
df_mas_cases['cum_vax'] = df_mas_cases['total_vax'].cumsum()
In [31]:
df_mas_deaths['total_vax'] = df_mas_deaths['deaths_pvax'] + df_mas_deaths['deaths_fvax']
df_mas_deaths['cum_deaths'] = df_mas_deaths['deaths_new_dod'].cumsum()
df_mas_deaths['cum_vax'] = df_mas_deaths['total_vax'].cumsum()
In [32]:
fig = make_subplots(shared_xaxes=True, specs=[[{'secondary_y': True}]])

#Graph 1
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_cases['cases_new'], name ='Positive Cases', 
               line = dict(color='blue', width=1)), secondary_y=True, row=1, col=1)
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_cases['cases_recovered'], name = 'Recovered Cases',
               line = dict(color='red', width=1)), secondary_y=True, row=1, col=1)
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_cases['total_vax'], name = 'Vax. Cases',
               line = dict(color='green', width=1)), secondary_y=True, row=1, col=1)
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_cases['cum_new'], name ='Cumulative Cases', 
               line = dict(color='blue', width=1)), secondary_y=False, row=1, col=1)
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_cases['cum_recovered'], name = 'Cumulative Recovered',
               line = dict(color='red', width=1)), secondary_y=False, row=1, col=1)
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_cases['cum_vax'], name = 'Cumulative Vax.',
               line = dict(color='green', width=1)), secondary_y=False, row=1, col=1)

fig.update_layout(title_text='Malaysia Covid19 New And Recovered Cases', title_x=0.5, showlegend=False,
                 height=600)
fig.update_xaxes(title_text='')
fig.update_annotations(font=dict(family="Helvetica", size=12))
fig.update_layout(font=dict(family="Helvetica", size=14))
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot", 
              x0='2021-10-11', x1='2021-10-11',  y0=0, y1=1000000)
fig.add_annotation(text='90% Vax.', x='2021-10-11', y=1000000, arrowhead=3, align='center', 
                   arrowsize=1, arrowwidth=2, arrowcolor="#636363",xref='x', ax=50, ay=-90, showarrow=True, 
                   xanchor="left", yanchor="bottom")
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot", 
              x0='2020-09-26', x1='2020-09-26',  y0=0, y1=500000)
fig.add_annotation(text='PRN Sabah', x='2020-09-26', y=500000, arrowhead=3, align='center', 
                   arrowsize=1, arrowwidth=2, arrowcolor="#636363",xref='x', ax=50, ay=-30, showarrow=True, 
                   xanchor="left", yanchor="bottom")
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot", 
              x0='2021-11-20', x1='2021-11-20',  y0=0, y1=500000)
fig.add_annotation(text='PRN Melaka', x='2021-11-20', y=500000, arrowhead=3, align='center', 
                   arrowsize=1, arrowwidth=2, arrowcolor="#636363",xref='x', ax=50, ay=-30, showarrow=True, 
                   xanchor="left", yanchor="bottom")
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot", 
              x0='2021-12-06', x1='2021-12-06',  y0=0, y1=400000)
fig.add_annotation(text='PRN Sarawak', x='2021-12-06', y=400000, arrowhead=3, align='center', 
                   arrowsize=1, arrowwidth=2, arrowcolor="#636363",xref='x', ax=50, ay=-30, showarrow=True, 
                   xanchor="left", yanchor="bottom")
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot", 
              x0='2021-01-12', x1='2021-01-12',  y0=0, y1=600000)
fig.add_annotation(text='Darurat Mula', x='2021-01-12', y=600000, arrowhead=3, align='center', 
                   arrowsize=1, arrowwidth=2, arrowcolor="#636363",xref='x', ax=50, ay=-30, showarrow=True, 
                   xanchor="left", yanchor="bottom")
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot", 
              x0='2021-08-01', x1='2021-08-01',  y0=0, y1=1100000)
fig.add_annotation(text='Darurat Tamat', x='2021-08-01', y=1100000, arrowhead=3, align='center', 
                   arrowsize=1, arrowwidth=2, arrowcolor="#636363",xref='x', ax=50, ay=-30, showarrow=True, 
                   xanchor="left", yanchor="bottom")
fig.show()
In [33]:
df_2020 = df_mas_cases.query("date >= '2020-01-01' \
                            and date <= '2020-12-31'")
df_2021 = df_mas_cases.query("date >= '2021-01-01' \
                            and date <= '2021-12-31'")
df_2022 = df_mas_cases.query("date >= '2022-01-01' \
                            and date <= '2022-12-31'")
In [34]:
fig = make_subplots(rows=1, cols=3, specs=[[{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}]],
                    
subplot_titles=('<b>Year 2020</b>',
                '<b>Year 2021</b>',
                '<b>Year 2022</b>'))

fig.add_trace(go.Scatter(x = df_2020['date'], y = df_2020['cases_new'], name = '2020',
               line = dict(color='green', width=1)), secondary_y=False, row=1, col=1)
fig.add_trace(go.Scatter(x = df_2021['date'], y = df_2021['cases_new'], name = '2021',
               line = dict(color='blue', width=1)), secondary_y=False, row=1, col=2)
fig.add_trace(go.Scatter(x = df_2022['date'], y = df_2022['cases_new'], name = '2022',
               line = dict(color='red', width=1)), secondary_y=False, row=1, col=3)
fig.update_layout(title_text='Malaysia Covid19 Cases By Year', title_x=0.5, showlegend=False,
                 height=350)
fig.update_xaxes(title_text='')
#Update Fonts & Size
fig.update_annotations(font=dict(family="Helvetica", size=11))
fig.update_layout(font=dict(family="Helvetica", size=11))
fig.update_layout(height=350,showlegend=False)
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')

#Plotting the graph
fig.show()
In [35]:
#Forecasting of New Cases VS Recovered Cases
#Importing the required module
from statsmodels.graphics.tsaplots import plot_acf, plot_pacf
from statsmodels.tsa.statespace.varmax import VARMAX
from statsmodels.tsa.api import VAR
#from statsmodels.tsa.stattools import grangercausalitytests, adfuller
from tqdm import tqdm_notebook
from itertools import product
import statsmodels.api as sm
import warnings
warnings.filterwarnings('ignore')
#Importing the required datasets
filepath_cases = 'https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/cases_malaysia.csv'
filepath_deaths = "https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/deaths_malaysia.csv"
filepath_vaksin = 'https://raw.githubusercontent.com/CITF-Malaysia/citf-public/main/vaccination/vax_malaysia.csv'
#Preparing the required datasets
filepath_cases = pd.read_csv(filepath_cases, parse_dates=['date'], index_col='date').astype('float64')
filepath_deaths = pd.read_csv(filepath_deaths, parse_dates=['date'], index_col='date').astype('float64')
filepath_vaksin = pd.read_csv(filepath_vaksin, parse_dates=['date'], index_col='date').astype('float64')
macro_data = pd.merge(filepath_cases,filepath_deaths,on='date')
macro_data = pd.merge(macro_data,filepath_vaksin,on='date')
macro_data['cases_vax_total'] = macro_data['cases_pvax'] + macro_data['cases_fvax']
macro_data['deaths_vax_total'] = macro_data['deaths_pvax'] + macro_data['deaths_fvax']
macro_data = macro_data[['cases_new','cases_vax_total']]
train_df=macro_data[:-12]
test_df=macro_data[-360:]
model = VAR(train_df.diff()[1:])
sorted_order=model.select_order(maxlags=30)
var_model = VARMAX(train_df, order=(4,0),enforce_stationarity= False)
fitted_model = var_model.fit(disp=True)
#Creating the required forecast
n_forecast = 180
predict = fitted_model.get_prediction(start=len(train_df),end=len(train_df) + n_forecast-1)
predictions=predict.predicted_mean
predictions.columns=['cases_predicted','cases_vax_total_predicted']
test_vs_pred=pd.concat([test_df,predictions],axis=1)
test_vs_pred = test_vs_pred.reset_index()
test_vs_pred['cases_new_cum'] = test_vs_pred['cases_new'].cumsum()
test_vs_pred['cases_vax_total_cum'] = test_vs_pred['cases_vax_total'].cumsum()
test_vs_pred['cases_predicted_cum'] = test_vs_pred['cases_predicted'].cumsum()
test_vs_pred['cases_vax_total_predicted_cum'] = test_vs_pred['cases_vax_total_predicted'].cumsum()
#Plotting the required forecast
fig = make_subplots(specs=[[{'secondary_y': True}]])
fig.add_trace(go.Scatter(x = test_vs_pred['index'], y = test_vs_pred['cases_new'], name ='Positive Cases', 
               line = dict(color='blue', width=1)), secondary_y=True)
fig.add_trace(go.Scatter(x = test_vs_pred['index'], y = test_vs_pred['cases_new_cum'], name ='Positive Cases', 
               line = dict(color='blue', width=1)), secondary_y=False)
fig.add_trace(go.Scatter(x = test_vs_pred['index'], y = test_vs_pred['cases_vax_total'], name = 'Positive Cases After Vaccinated',
               line = dict(color='red', width=1)), secondary_y=True)
fig.add_trace(go.Scatter(x = test_vs_pred['index'], y = test_vs_pred['cases_vax_total_cum'], name = 'Positive Cases After Vaccinated',
               line = dict(color='red', width=1)), secondary_y=False)
fig.add_trace(go.Scatter(x = test_vs_pred['index'], y = test_vs_pred['cases_predicted'], name = 'Predicted Positive Cases',
              line = dict(color='blue', width=0.75)), secondary_y=True)
fig.add_trace(go.Scatter(x = test_vs_pred['index'], y = test_vs_pred['cases_vax_total_predicted'], name = 'Predicted Positive Cases After Vaccinated',
              line = dict(color='red', width=0.75)), secondary_y=True)


fig.update_layout(title_text='Malaysia Covid19 Forecast of Positive & Active Cases (Based on VAR Model)', 
                  title_x=0.5,showlegend=False, height=600)
fig.update_xaxes(title_text='')
fig.update_annotations(font=dict(family="Helvetica", size=12))
fig.update_layout(font=dict(family="Helvetica", size=14))
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot", 
              x0='2021-10-11', x1='2021-10-11',  y0=0, y1=800000)
fig.add_annotation(text='90% Adult Vax.', x='2021-10-11', y=800000, arrowhead=3, align='center', 
                   arrowsize=1, arrowwidth=2, arrowcolor="#636363",xref='x', ax=50, ay=-90, showarrow=True, 
                   xanchor="left", yanchor="bottom")
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot", 
              x0='2021-11-20', x1='2021-11-20',  y0=0, y1=600000)
fig.add_annotation(text='PRN Melaka', x='2021-11-20', y=600000, arrowhead=3, align='center', 
                   arrowsize=1, arrowwidth=2, arrowcolor="#636363",xref='x', ax=50, ay=-90, showarrow=True, 
                   xanchor="left", yanchor="bottom")
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot", 
              x0='2021-12-06', x1='2021-12-06',  y0=0, y1=500000)
fig.add_annotation(text='PRN Sarawak', x='2021-12-06', y=500000, arrowhead=3, align='center', 
                   arrowsize=1, arrowwidth=2, arrowcolor="#636363",xref='x', ax=50, ay=-90, showarrow=True, 
                   xanchor="left", yanchor="bottom")
fig.show()
In [36]:
df = df_states_cases
df_joh = df[df.state == 'Johor']
df_ked = df[df.state == 'Kedah']
df_kel = df[df.state == 'Kelantan']
df_mel = df[df.state == 'Melaka']
df_neg = df[df.state == 'Negeri Sembilan']
df_pah = df[df.state == 'Pahang']
df_prk = df[df.state == 'Perak']
df_per = df[df.state == 'Perlis']
df_pen = df[df.state == 'Pulau Pinang']
df_sab = df[df.state == 'Sabah']
df_sar = df[df.state == 'Sarawak']
df_sel = df[df.state == 'Selangor']
df_ter = df[df.state == 'Terengganu']
df_kul = df[df.state == 'W.P. Kuala Lumpur']
df_lab = df[df.state == 'W.P. Labuan']
df_put = df[df.state == 'W.P. Putrajaya']
fig = make_subplots(rows=4, cols=4, specs=[[{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}]],
                    
subplot_titles=('<b>Johor</b>', '<b>Kedah</b>', '<b>Kelantan</b>', '<b>Melaka</b>',
                '<b>Negeri Sembilan</b>', '<b>Pahang</b>', '<b>Perak</b>', '<b>Perlis</b>',
                '<b>Pulau Pinang</b>', '<b>Sabah</b>', '<b>Sarawak</b>', '<b>Selangor</b>',
                '<b>Terengganu</b>', '<b>W.P. Kuala Lumpur</b>', '<b>W.P. Labuan</b>', '<b>W.P. Putrajaya</b>'))
#Graph 1
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=1, col=1,secondary_y=False)
fig.add_hline(y=df_joh['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=1, col=1)
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=1, col=1,secondary_y=True)
#Graph 2
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=1, col=2,secondary_y=False)
fig.add_hline(y=df_ked['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=1, col=2)
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=1, col=2,secondary_y=True)
#Graph 3
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=1, col=3,secondary_y=False)
fig.add_hline(y=df_kel['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=1, col=3)
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=1, col=3,secondary_y=True)
#Graph 4
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=1, col=4,secondary_y=False)
fig.add_hline(y=df_mel['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=1, col=4)
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=1, col=4,secondary_y=True)
#Graph 5
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=2, col=1,secondary_y=False)
fig.add_hline(y=df_neg['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=2, col=1)
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=2, col=1,secondary_y=True)
#Graph 6
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=2, col=2,secondary_y=False)
fig.add_hline(y=df_pah['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=2, col=2)
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=2, col=2,secondary_y=True)
#Graph 7
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=2, col=3,secondary_y=False)
fig.add_hline(y=df_prk['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=2, col=3)
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=2, col=3,secondary_y=True)
#Graph 8
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=2, col=4,secondary_y=False)
fig.add_hline(y=df_per['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=2, col=4)
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=2, col=4,secondary_y=True)
#Graph 9
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=3, col=1,secondary_y=False)
fig.add_hline(y=df_pen['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=3, col=1)
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=3, col=1,secondary_y=True)
#Graph 10
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=3, col=2,secondary_y=False)
fig.add_hline(y=df_sab['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=3, col=2)
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=3, col=2,secondary_y=True)
#Graph 11
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=3, col=3,secondary_y=False)
fig.add_hline(y=df_sar['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=3, col=3)
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=3, col=3,secondary_y=True)
#Graph 12
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=3, col=4,secondary_y=False)
fig.add_hline(y=df_sel['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=3, col=4)
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=3, col=4,secondary_y=True)
#Graph 13
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=4, col=1,secondary_y=False)
fig.add_hline(y=df_ter['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=4, col=1)
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=4, col=1,secondary_y=True)
#Graph 14
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=4, col=2,secondary_y=False)
fig.add_hline(y=df_kul['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=4, col=2)
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=4, col=2,secondary_y=True)
#Graph 15
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=4, col=3,secondary_y=False)
fig.add_hline(y=df_lab['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=4, col=3)
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=4, col=3,secondary_y=True)
#Graph 16
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=4, col=4,secondary_y=False)
fig.add_hline(y=df_put['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=4, col=4)
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=4, col=4,secondary_y=True)
#Adding title and adjusting the layout
fig.update_layout(height=1000,showlegend=False,title_text="Covid19 Cases & Recovered At Each States",title_x=0.5)
fig.update_annotations(font=dict(family="Helvetica", size=10))
fig.update_layout(font=dict(family="Helvetica", size=12))
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
#Plotting the graph
fig.show()
In [37]:
df = df_states_deaths
df['deaths_vax_total'] = df['deaths_fvax'] + df['deaths_pvax'] 
df_joh = df[df.state == 'Johor']
df_ked = df[df.state == 'Kedah']
df_kel = df[df.state == 'Kelantan']
df_mel = df[df.state == 'Melaka']
df_neg = df[df.state == 'Negeri Sembilan']
df_pah = df[df.state == 'Pahang']
df_prk = df[df.state == 'Perak']
df_per = df[df.state == 'Perlis']
df_pen = df[df.state == 'Pulau Pinang']
df_sab = df[df.state == 'Sabah']
df_sar = df[df.state == 'Sarawak']
df_sel = df[df.state == 'Selangor']
df_ter = df[df.state == 'Terengganu']
df_kul = df[df.state == 'W.P. Kuala Lumpur']
df_lab = df[df.state == 'W.P. Labuan']
df_put = df[df.state == 'W.P. Putrajaya']
fig = make_subplots(rows=4, cols=4, specs=[[{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}]],
                    
subplot_titles=('<b>Johor</b>', '<b>Kedah</b>', '<b>Kelantan</b>', '<b>Melaka</b>',
                '<b>Negeri Sembilan</b>', '<b>Pahang</b>', '<b>Perak</b>', '<b>Perlis</b>',
                '<b>Pulau Pinang</b>', '<b>Sabah</b>', '<b>Sarawak</b>', '<b>Selangor</b>',
                '<b>Terengganu</b>', '<b>W.P. Kuala Lumpur</b>', '<b>W.P. Labuan</b>', '<b>W.P. Putrajaya</b>'))
#Graph 1
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=1, col=1,secondary_y=False)
fig.add_hline(y=df_joh['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=1, col=1)
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=1, col=1,secondary_y=False)
#Graph 2
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=1, col=2,secondary_y=False)
fig.add_hline(y=df_ked['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=1, col=2)
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=1, col=2,secondary_y=False)
#Graph 3
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=1, col=3,secondary_y=False)
fig.add_hline(y=df_kel['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=1, col=3)
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=1, col=3,secondary_y=False)
#Graph 4
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=1, col=4,secondary_y=False)
fig.add_hline(y=df_mel['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=1, col=4)
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=1, col=4,secondary_y=False)
#Graph 5
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=2, col=1,secondary_y=False)
fig.add_hline(y=df_neg['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=2, col=1)
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=2, col=1,secondary_y=False)
#Graph 6
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=2, col=2,secondary_y=False)
fig.add_hline(y=df_pah['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=2, col=2)
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=2, col=2,secondary_y=False)
#Graph 7
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=2, col=3,secondary_y=False)
fig.add_hline(y=df_prk['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=2, col=3)
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=2, col=3,secondary_y=False)
#Graph 8
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=2, col=4,secondary_y=False)
fig.add_hline(y=df_per['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=2, col=4)
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=2, col=4,secondary_y=False)
#Graph 9
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=3, col=1,secondary_y=False)
fig.add_hline(y=df_pen['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=3, col=1)
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=3, col=1,secondary_y=False)
#Graph 10
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=3, col=2,secondary_y=False)
fig.add_hline(y=df_sab['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=3, col=2)
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=3, col=2,secondary_y=False)
#Graph 11
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=3, col=3,secondary_y=False)
fig.add_hline(y=df_sar['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=3, col=3)
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=3, col=3,secondary_y=False)
#Graph 12
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=3, col=4,secondary_y=False)
fig.add_hline(y=df_sel['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=3, col=4)
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=3, col=4,secondary_y=False)
#Graph 13
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=4, col=1,secondary_y=False)
fig.add_hline(y=df_ter['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=4, col=1)
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=4, col=1,secondary_y=False)
#Graph 14
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=4, col=2,secondary_y=False)
fig.add_hline(y=df_kul['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=4, col=2)
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=4, col=2,secondary_y=False)
#Graph 15
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=4, col=3,secondary_y=False)
fig.add_hline(y=df_lab['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=4, col=3)
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=4, col=3,secondary_y=False)
#Graph 16
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=4, col=4,secondary_y=False)
fig.add_hline(y=df_put['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=4, col=4)
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=4, col=4,secondary_y=False)
#Adding title and adjusting the layout
fig.update_layout(height=1000,showlegend=False,title_text="Covid19 Daily Deaths Total & Vaccinated At Each States",title_x=0.5)
fig.update_annotations(font=dict(family="Helvetica", size=10))
fig.update_layout(font=dict(family="Helvetica", size=12))
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
#Plotting the graph
fig.show()
In [38]:
#Extracting And Separating Data For Each States
#Johor
df = df_states_vaksin
df_joh = df[df.state == 'Johor']
df_joh['cum_partial'] = df_joh['daily_partial'].cumsum()
df_joh['cum_full'] = df_joh['daily_full'].cumsum()
df_joh['cum_booster'] = df_joh['daily_booster'].cumsum()
#Kedah
df_ked = df[df.state == 'Kedah']
df_ked['cum_partial'] = df_ked['daily_partial'].cumsum()
df_ked['cum_full'] = df_ked['daily_full'].cumsum()
df_ked['cum_booster'] = df_ked['daily_booster'].cumsum()
#Kelantan
df_kel = df[df.state == 'Kelantan']
df_kel['cum_partial'] = df_kel['daily_partial'].cumsum()
df_kel['cum_full'] = df_kel['daily_full'].cumsum()
df_kel['cum_booster'] = df_kel['daily_booster'].cumsum()
#Melaka
df_mel = df[df.state == 'Melaka']
df_mel['cum_partial'] = df_mel['daily_partial'].cumsum()
df_mel['cum_full'] = df_mel['daily_full'].cumsum()
df_mel['cum_booster'] = df_mel['daily_booster'].cumsum()
#Negeri Sembilan
df_neg = df[df.state == 'Negeri Sembilan']
df_neg['cum_partial'] = df_neg['daily_partial'].cumsum()
df_neg['cum_full'] = df_neg['daily_full'].cumsum()
df_neg['cum_booster'] = df_neg['daily_booster'].cumsum()
#Pahang
df_pah = df[df.state == 'Pahang']
df_pah['cum_partial'] = df_pah['daily_partial'].cumsum()
df_pah['cum_full'] = df_pah['daily_full'].cumsum()
df_pah['cum_booster'] = df_pah['daily_booster'].cumsum()
#Perak
df_prk = df[df.state == 'Perak']
df_prk['cum_partial'] = df_prk['daily_partial'].cumsum()
df_prk['cum_full'] = df_prk['daily_full'].cumsum()
df_prk['cum_booster'] = df_prk['daily_booster'].cumsum()
#Perlis
df_per = df[df.state == 'Perlis']
df_per['cum_partial'] = df_per['daily_partial'].cumsum()
df_per['cum_full'] = df_per['daily_full'].cumsum()
df_per['cum_booster'] = df_per['daily_booster'].cumsum()
#Pulau Pinang
df_pen = df[df.state == 'Pulau Pinang']
df_pen['cum_partial'] = df_pen['daily_partial'].cumsum()
df_pen['cum_full'] = df_pen['daily_full'].cumsum()
df_pen['cum_booster'] = df_pen['daily_booster'].cumsum()
#Sabah
df_sab = df[df.state == 'Sabah']
df_sab['cum_partial'] = df_sab['daily_partial'].cumsum()
df_sab['cum_full'] = df_sab['daily_full'].cumsum()
df_sab['cum_booster'] = df_sab['daily_booster'].cumsum()
#Sarawak
df_sar = df[df.state == 'Sarawak']
df_sar['cum_partial'] = df_sar['daily_partial'].cumsum()
df_sar['cum_full'] = df_sar['daily_full'].cumsum()
df_sar['cum_booster'] = df_sar['daily_booster'].cumsum()
#Selangor
df_sel = df[df.state == 'Selangor']
df_sel['cum_partial'] = df_sel['daily_partial'].cumsum()
df_sel['cum_full'] = df_sel['daily_full'].cumsum()
df_sel['cum_booster'] = df_sel['daily_booster'].cumsum()
#Terengganu
df_ter = df[df.state == 'Terengganu']
df_ter['cum_partial'] = df_ter['daily_partial'].cumsum()
df_ter['cum_full'] = df_ter['daily_full'].cumsum()
df_ter['cum_booster'] = df_ter['daily_booster'].cumsum()
#Kuala Lumpur
df_kul = df[df.state == 'W.P. Kuala Lumpur']
df_kul['cum_partial'] = df_kul['daily_partial'].cumsum()
df_kul['cum_full'] = df_kul['daily_full'].cumsum()
df_kul['cum_booster'] = df_kul['daily_booster'].cumsum()
#Labuan
df_lab = df[df.state == 'W.P. Labuan']
df_lab['cum_partial'] = df_lab['daily_partial'].cumsum()
df_lab['cum_full'] = df_lab['daily_full'].cumsum()
df_lab['cum_booster'] = df_lab['daily_booster'].cumsum()
#Putrajaya
df_put = df[df.state == 'W.P. Putrajaya']
df_put['cum_partial'] = df_put['daily_partial'].cumsum()
df_put['cum_full'] = df_put['daily_full'].cumsum()
df_put['cum_booster'] = df_put['daily_booster'].cumsum()
In [39]:
fig = make_subplots(rows=4, cols=4, specs=[[{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}]],
                    
subplot_titles=('<b>Johor</b>', '<b>Kedah</b>', '<b>Kelantan</b>', '<b>Melaka</b>',
                '<b>Negeri Sembilan</b>', '<b>Pahang</b>', '<b>Perak</b>', '<b>Perlis</b>',
                '<b>Pulau Pinang</b>', '<b>Sabah</b>', '<b>Sarawak</b>', '<b>Selangor</b>',
                '<b>Terengganu</b>', '<b>W.P. Kuala Lumpur</b>', '<b>W.P. Labuan</b>', '<b>W.P. Putrajaya</b>'))
#Graph 1
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=1, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=1, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=1, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=1, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=1, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=1, col=1,secondary_y=False)
#Graph 2
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=1, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=1, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=1, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=1, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=1, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=1, col=2,secondary_y=False)
#Graph 3
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=1, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=1, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=1, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=1, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=1, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=1, col=3,secondary_y=False)
#Graph 4
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=1, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=1, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=1, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=1, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=1, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=1, col=4,secondary_y=False)
#Graph 5
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=2, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=2, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=2, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=2, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=2, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=2, col=1,secondary_y=False)
#Graph 6
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=2, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=2, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=2, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=2, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=2, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=2, col=2,secondary_y=False)
#Graph 7
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=2, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=2, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=2, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=2, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=2, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=2, col=3,secondary_y=False)
#Graph 8
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=2, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=2, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=2, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=2, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=2, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=2, col=4,secondary_y=False)
#Graph 9
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=3, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=3, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=3, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=3, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=3, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=3, col=1,secondary_y=False)
#Graph 10
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=3, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=3, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=3, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=3, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=3, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=3, col=2,secondary_y=False)
#Graph 11
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=3, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=3, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=3, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=3, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=3, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=3, col=3,secondary_y=False)
#Graph 12
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=3, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=3, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=3, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=3, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=3, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=3, col=4,secondary_y=False)
#Graph 13
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=4, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=4, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=4, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=4, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=4, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=4, col=1,secondary_y=False)
#Graph 14
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=4, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=4, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=4, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=4, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=4, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=4, col=2,secondary_y=False)
#Graph 15
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=4, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=4, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=4, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=4, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=4, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=4, col=3,secondary_y=False)
#Graph 16
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=4, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=4, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=4, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=4, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=4, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=4, col=4,secondary_y=False)
#Adding title and adjusting the layout
fig.update_layout(height=1000,showlegend=False,title_text="Covid19 Daily Vaccination (1D, 2D & 3D) At Each States",title_x=0.5)
fig.update_annotations(font=dict(family="Helvetica", size=10))
fig.update_layout(font=dict(family="Helvetica", size=12))
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
#Plotting the graph
fig.show()
In [40]:
dfpop = df_states_pop
#Creating new vax percentage columns at each states
#Johor
df_joh_pop = dfpop[dfpop.state == 'Johor']
df_joh_pop = df_joh_pop.at[df_joh_pop.index[0],'pop']
df_joh['2 Dos (%)'] = (df_joh['cum_full']/df_joh_pop)*100
#Kedah
df_ked_pop = dfpop[dfpop.state == 'Kedah']
df_ked_pop = df_ked_pop.at[df_ked_pop.index[0],'pop']
df_ked['2 Dos (%)'] = (df_ked['cum_full']/df_ked_pop)*100
#Kelantan
df_kel_pop = dfpop[dfpop.state == 'Kelantan']
df_kel_pop = df_kel_pop.at[df_kel_pop.index[0],'pop']
df_kel['2 Dos (%)'] = (df_kel['cum_full']/df_kel_pop)*100
#Melaka
df_mel_pop = dfpop[dfpop.state == 'Melaka']
df_mel_pop = df_mel_pop.at[df_mel_pop.index[0],'pop']
df_mel['2 Dos (%)'] = (df_mel['cum_full']/df_mel_pop)*100
#Negeri Sembilan
df_neg_pop = dfpop[dfpop.state == 'Negeri Sembilan']
df_neg_pop = df_neg_pop.at[df_neg_pop.index[0],'pop']
df_neg['2 Dos (%)'] = (df_neg['cum_full']/df_neg_pop)*100
#Pahang
df_pah_pop = dfpop[dfpop.state == 'Pahang']
df_pah_pop = df_pah_pop.at[df_pah_pop.index[0],'pop']
df_pah['2 Dos (%)'] = (df_pah['cum_full']/df_pah_pop)*100
#Perak
df_prk_pop = dfpop[dfpop.state == 'Perak']
df_prk_pop = df_prk_pop.at[df_prk_pop.index[0],'pop']
df_prk['2 Dos (%)'] = (df_prk['cum_full']/df_prk_pop)*100
#Perlis
df_per_pop = dfpop[dfpop.state == 'Perlis']
df_per_pop = df_per_pop.at[df_per_pop.index[0],'pop']
df_per['2 Dos (%)'] = (df_per['cum_full']/df_per_pop)*100
#Penang
df_pen_pop = dfpop[dfpop.state == 'Pulau Pinang']
df_pen_pop = df_pen_pop.at[df_pen_pop.index[0],'pop']
df_pen['2 Dos (%)'] = (df_pen['cum_full']/df_pen_pop)*100
#Sabah
df_sab_pop = dfpop[dfpop.state == 'Sabah']
df_sab_pop = df_sab_pop.at[df_sab_pop.index[0],'pop']
df_sab['2 Dos (%)'] = (df_sab['cum_full']/df_sab_pop)*100
#Sarawak
df_sar_pop = dfpop[dfpop.state == 'Sarawak']
df_sar_pop = df_sar_pop.at[df_sar_pop.index[0],'pop']
df_sar['2 Dos (%)'] = (df_sar['cum_full']/df_sar_pop)*100
#Selangor
df_sel_pop = dfpop[dfpop.state == 'Selangor']
df_sel_pop = df_sel_pop.at[df_sel_pop.index[0],'pop']
df_sel['2 Dos (%)'] = (df_sel['cum_full']/df_sel_pop)*100
#Terengganu
df_ter_pop = dfpop[dfpop.state == 'Terengganu']
df_ter_pop = df_ter_pop.at[df_ter_pop.index[0],'pop']
df_ter['2 Dos (%)'] = (df_ter['cum_full']/df_ter_pop)*100
#Kuala Lumpur
df_kul_pop = dfpop[dfpop.state == 'W.P. Kuala Lumpur']
df_kul_pop = df_kul_pop.at[df_kul_pop.index[0],'pop']
df_kul['2 Dos (%)'] = (df_kul['cum_full']/df_kul_pop)*100
#Labuan
df_lab_pop = dfpop[dfpop.state == 'W.P. Labuan']
df_lab_pop = df_lab_pop.at[df_lab_pop.index[0],'pop']
df_lab['2 Dos (%)'] = (df_lab['cum_full']/df_lab_pop)*100
#Putrajaya
df_put_pop = dfpop[dfpop.state == 'W.P. Putrajaya']
df_put_pop = df_put_pop.at[df_put_pop.index[0],'pop']
df_put['2 Dos (%)'] = (df_put['cum_full']/df_put_pop)*100
#Start creating the graph
fig = make_subplots(rows=4, cols=4, specs=[[{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}]],
                    
subplot_titles=('<b>Johor</b>', '<b>Kedah</b>', '<b>Kelantan</b>', '<b>Melaka</b>',
                '<b>Negeri Sembilan</b>', '<b>Pahang</b>', '<b>Perak</b>', '<b>Perlis</b>',
                '<b>Pulau Pinang</b>', '<b>Sabah</b>', '<b>Sarawak</b>', '<b>Selangor</b>',
                '<b>Terengganu</b>', '<b>W.P. Kuala Lumpur</b>', '<b>W.P. Labuan</b>', '<b>W.P. Putrajaya</b>'))
#Graph 1
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=1, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=1, col=1,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=1, col=1)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=1, col=1)
#Graph 2
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=1, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=1, col=2,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=1, col=2)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=1, col=2)
#Graph 3
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=1, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=1, col=3,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=1, col=3)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=1, col=3)
#Graph 4
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=1, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=1, col=4,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=1, col=4)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=1, col=4)
#Graph 5
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=2, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=2, col=1,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=2, col=1)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=2, col=1)
#Graph 6
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=2, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=2, col=2,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=2, col=2)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=2, col=2)
#Graph 7
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=2, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=2, col=3,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=2, col=3)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=2, col=3)
#Graph 8
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=2, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=2, col=4,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=2, col=4)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=2, col=4)
#Graph 9
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=3, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=3, col=1,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=3, col=1)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=3, col=1)
#Graph 10
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=3, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=3, col=2,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=3, col=2)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=3, col=2)
#Graph 11
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=3, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=3, col=3,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=3, col=3)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=3, col=3)
#Graph 12
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=3, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=3, col=4,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=3, col=4)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=3, col=4)
#Graph 13
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=4, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=4, col=1,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=4, col=1)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=4, col=1)
#Graph 14
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=4, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=4, col=2,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=4, col=2)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=4, col=2)
#Graph 15
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=4, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=4, col=3,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=4, col=3)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=4, col=3)
#Graph 16
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=4, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=4, col=4,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=4, col=4)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=4, col=4)
#Adding title and adjusting the layout
fig.update_layout(height=1000,showlegend=False,
                  title_text="Covid19 Vaccination Against Vaccination Per Population At Each States",title_x=0.5)
fig.update_annotations(font=dict(family="Helvetica", size=10))
fig.update_layout(font=dict(family="Helvetica", size=12))
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
#Plotting the graph
fig.show()
In [41]:
#Retrieving dataset for Covid19 for all countries
dfworld = pd.read_csv('https://raw.githubusercontent.com/datasets/covid-19/main/data/time-series-19-covid-combined.csv')
dfworld['daily_cases'] = dfworld['Confirmed'].diff()
dfworld['daily_recover'] = dfworld['Recovered'].diff()
dfworld['daily_deaths'] = dfworld['Deaths'].diff()
In [42]:
dfworld2 = pd.read_csv('https://raw.githubusercontent.com/owid/covid-19-data/master/public/data/latest/owid-covid-latest.csv')
dfworld2 = dfworld2[dfworld2['continent'].notna()] 
dfworld2 = dfworld2[['location','total_cases','total_deaths','people_vaccinated',
                     'population','population_density','gdp_per_capita']]
dfworld2['Cases (%)'] = (dfworld2['total_cases']/dfworld2['population'])*100
dfworld2['Deaths (%)'] = (dfworld2['total_deaths']/dfworld2['total_cases'])*100
dfworld2['Vaccination (%)'] = (dfworld2['people_vaccinated']/dfworld2['population'])*100

dfworld2.rename(columns={'location':'Country','total_cases':'Total Cases','total_deaths':'Total Deaths',
                         'people_vaccinated':'People Vaccinated','population':'Population',
                         'population_density':'Population Density','gdp_per_capita':'GDP Per Kapita'},inplace=True)
In [43]:
df_asean = dfworld2.loc[dfworld2['Country'].isin(['Malaysia','Singapore','Thailand','Indonesia',
                                              'Philippines','Cambodia','Laos','Vietnam',
                                              'Myanmar','Brunei'])]
df_asean = df_asean.sort_values('Total Cases',ascending=False)
def highlight_max(s):
    '''
    highlight the maximum in a Series Salmon.
    '''
    is_max = s == s.max()
    return ['background-color: salmon' if v else '' for v in is_max]

df_asean.style.set_caption("Overview Of Covid19 Cases In ASEAN Countries").set_table_styles([{
    'selector': 'caption',
    'props': [
        ('color', 'black'),
        ('font-size', '26px'),
        ("text-align", "center"),
        ('text-decoration', 'underline'),
        ('font-family','Arial'),
        ('text-shadow', '2px 2px 5px grey')
    ]},(dict
        (selector='th',props=[('text-align',
                               'left')]))]).format(
    {'Total Cases':'{:,.0f}','Total Deaths':'{:,.0f}','People Vaccinated':'{:,.0f}','Population':'{:,.0f}',
     'Population Density':'{:,.1f}','GDP Per Kapita':'{:,.1f}','Cases (%)':'{:,.1f}','Deaths (%)':'{:,.1f}',
     'Vaccination (%)':'{:,.1f}'}).set_properties(subset=['Country'],**{'text-align': 'left'}).hide_index().apply(
    highlight_max,subset=['Total Cases','Total Deaths','People Vaccinated','Population','Population Density',
                          'GDP Per Kapita','Cases (%)','Deaths (%)','Vaccination (%)'])
Out[43]:
Overview Of Covid19 Cases In ASEAN Countries
Country Total Cases Total Deaths People Vaccinated Population Population Density GDP Per Kapita Cases (%) Deaths (%) Vaccination (%)
Indonesia 4,763,252 145,065 188,060,706 276,361,788 145.7 11,188.7 1.7 3.0 68.0
Philippines 3,634,368 54,930 nan 111,046,910 351.9 7,599.2 3.3 1.5 nan
Malaysia 3,019,163 32,114 26,221,434 32,776,195 96.3 26,808.2 9.2 1.1 80.0
Thailand 2,593,327 22,436 52,785,968 69,950,844 135.1 16,277.7 3.7 0.9 75.5
Vietnam 2,484,481 38,862 79,162,150 98,168,829 308.1 6,171.9 2.5 1.6 80.6
Myanmar 545,298 19,310 nan 54,806,014 81.7 5,591.6 1.0 3.5 nan
Singapore 460,075 893 4,948,618 5,453,600 7,915.7 85,535.4 8.4 0.2 90.7
Laos 138,765 591 nan 7,379,358 29.7 6,397.4 1.9 0.4 nan
Cambodia 123,042 3,015 14,369,167 16,946,446 90.7 3,645.1 0.7 2.5 84.8
Brunei 21,579 98 nan 441,532 81.3 71,809.3 4.9 0.5 nan
In [44]:
#Selecting datasets for ASEAN Countries
#Malaysia
dfworld.rename(columns={'Country/Region':'Country'},inplace=True)
df_mas = dfworld[dfworld.Country == 'Malaysia']
df_mas = df_mas.reset_index(drop=True)
df_mas = df_mas.drop([0])
#Indonesia
df_ind = dfworld[dfworld.Country == 'Indonesia']
df_ind = df_ind.reset_index(drop=True)
df_ind = df_ind.drop([0])
#Philippines
df_phi = dfworld[dfworld.Country == 'Philippines']
df_phi = df_phi.reset_index(drop=True)
df_phi = df_phi.drop([0])
#Burma
df_bur = dfworld[dfworld.Country == 'Burma']
df_bur = df_bur.reset_index(drop=True)
df_bur = df_bur.drop([0])
#Singapore
df_sin = dfworld[dfworld.Country == 'Singapore']
df_sin = df_sin.reset_index(drop=True)
df_sin = df_sin.drop([0])
#Thailand
df_tha = dfworld[dfworld.Country == 'Thailand']
df_tha = df_tha.reset_index(drop=True)
df_tha = df_tha.drop([0])
#Vietnam
df_vie = dfworld[dfworld.Country == 'Vietnam']
df_vie = df_vie.reset_index(drop=True)
df_vie = df_vie.drop([0])
#Cambodia
df_cam = dfworld[dfworld.Country == 'Cambodia']
df_cam = df_cam.reset_index(drop=True)
df_cam = df_cam.drop([0])
#Brunei
df_bru = dfworld[dfworld.Country == 'Brunei']
df_bru = df_bru.reset_index(drop=True)
df_bru = df_bru.drop([0])
#Laos
df_lao = dfworld[dfworld.Country == 'Laos']
df_lao = df_lao.reset_index(drop=True)
df_lao = df_lao.drop([0])
In [45]:
#Creating the ASEAN Covid19 Cases Graphs
fig = make_subplots(rows=2, cols=5, specs=[[{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}, {'secondary_y': True}]],
                    
subplot_titles=('<b>Malaysia</b>', '<b>Indonesia</b>', '<b>Philippines</b>', '<b>Burma</b>', '<b>Singapore</b>',
                '<b>Thailand</b>', '<b>Vietnam</b>', '<b>Cambodia</b>', '<b>Brunei</b>', '<b>Laos</b>'))
#Row 1
#Graph 1
fig.add_trace(go.Scatter(x = df_mas['Date'], y = df_mas['Confirmed'],name='Total Cases',
                        line = dict(color='red', width=2)), row=1, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_mas['Date'], y = df_mas['daily_cases'],name='Daily Cases',
                        line = dict(color='blue', width=0.75)), row=1, col=1,secondary_y=True)
#Graph 2
fig.add_trace(go.Scatter(x = df_ind['Date'], y = df_ind['Confirmed'],name='Total Cases',
                        line = dict(color='red', width=2)), row=1, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_ind['Date'], y = df_ind['daily_cases'],name='Daily Cases',
                        line = dict(color='blue', width=0.75)), row=1, col=2,secondary_y=True)
#Graph 3
fig.add_trace(go.Scatter(x = df_phi['Date'], y = df_phi['Confirmed'],name='Total Cases',
                        line = dict(color='red', width=2)), row=1, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_phi['Date'], y = df_phi['daily_cases'],name='Daily Cases',
                        line = dict(color='blue', width=0.75)), row=1, col=3,secondary_y=True)
#Graph 4
fig.add_trace(go.Scatter(x = df_bur['Date'], y = df_bur['Confirmed'],name='Total Cases',
                        line = dict(color='red', width=2)), row=1, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_bur['Date'], y = df_bur['daily_cases'],name='Daily Cases',
                        line = dict(color='blue', width=0.75)), row=1, col=4,secondary_y=True)
#Graph 5
fig.add_trace(go.Scatter(x = df_sin['Date'], y = df_sin['Confirmed'],name='Total Cases',
                        line = dict(color='red', width=2)), row=1, col=5,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sin['Date'], y = df_sin['daily_cases'],name='Daily Cases',
                        line = dict(color='blue', width=0.75)), row=1, col=5,secondary_y=True)
#Row 2
#Graph 6
fig.add_trace(go.Scatter(x = df_tha['Date'], y = df_tha['Confirmed'],name='Total Cases',
                        line = dict(color='red', width=2)), row=2, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_tha['Date'], y = df_tha['daily_cases'],name='Daily Cases',
                        line = dict(color='blue', width=0.75)), row=2, col=1,secondary_y=True)
#Graph 7
fig.add_trace(go.Scatter(x = df_vie['Date'], y = df_vie['Confirmed'],name='Total Cases',
                        line = dict(color='red', width=2)), row=2, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_vie['Date'], y = df_vie['daily_cases'],name='Daily Cases',
                        line = dict(color='blue', width=0.75)), row=2, col=2,secondary_y=True)
#Graph 8
fig.add_trace(go.Scatter(x = df_cam['Date'], y = df_cam['Confirmed'],name='Total Cases',
                        line = dict(color='red', width=2)), row=2, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_cam['Date'], y = df_cam['daily_cases'],name='Daily Cases',
                        line = dict(color='blue', width=0.75)), row=2, col=3,secondary_y=True)
#Graph 9
fig.add_trace(go.Scatter(x = df_bru['Date'], y = df_bru['Confirmed'],name='Total Cases',
                        line = dict(color='red', width=2)), row=2, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_bru['Date'], y = df_bru['daily_cases'],name='Daily Cases',
                        line = dict(color='blue', width=0.75)), row=2, col=4,secondary_y=True)
#Graph 10
fig.add_trace(go.Scatter(x = df_lao['Date'], y = df_lao['Confirmed'],name='Total Cases',
                        line = dict(color='red', width=2)), row=2, col=5,secondary_y=False)
fig.add_trace(go.Scatter(x = df_lao['Date'], y = df_lao['daily_cases'],name='Daily Cases',
                        line = dict(color='blue', width=0.75)), row=2, col=5,secondary_y=True)

#Adding title and adjusting the layout
fig.update_layout(height=500,showlegend=False,title_text="Covid19 Total And Daily Cases At ASEAN Countries",title_x=0.5)
fig.update_annotations(font=dict(family="Helvetica", size=10))
fig.update_layout(font=dict(family="Helvetica", size=12))
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
#Plotting the graph
fig.show()
In [46]:
#Creating the ASEAN Covid19 Cases Graphs
fig = make_subplots(rows=2, cols=5, specs=[[{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}, {'secondary_y': True}]],
                    
subplot_titles=('<b>Malaysia</b>', '<b>Indonesia</b>', '<b>Philippines</b>', '<b>Burma</b>', '<b>Singapore</b>',
                '<b>Thailand</b>', '<b>Vietnam</b>', '<b>Cambodia</b>', '<b>Brunei</b>', '<b>Laos</b>'))
#Row 1
#Graph 1
fig.add_trace(go.Scatter(x = df_mas['Date'], y = df_mas['Deaths'],name='Total Deaths',
                        line = dict(color='blue', width=2)), row=1, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_mas['Date'], y = df_mas['daily_deaths'],name=' Daily Deaths',
                        line = dict(color='red', width=0.75)), row=1, col=1,secondary_y=True)
#Graph 2
fig.add_trace(go.Scatter(x = df_ind['Date'], y = df_ind['Deaths'],name='Total Deaths',
                        line = dict(color='blue', width=2)), row=1, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_ind['Date'], y = df_ind['daily_deaths'],name=' Daily Deaths',
                        line = dict(color='red', width=0.75)), row=1, col=2,secondary_y=True)
#Graph 3
fig.add_trace(go.Scatter(x = df_phi['Date'], y = df_phi['Deaths'],name='Total Deaths',
                        line = dict(color='blue', width=2)), row=1, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_phi['Date'], y = df_phi['daily_deaths'],name=' Daily Deaths',
                        line = dict(color='red', width=0.75)), row=1, col=3,secondary_y=True)
#Graph 4
fig.add_trace(go.Scatter(x = df_bur['Date'], y = df_bur['Deaths'],name='Total Deaths',
                        line = dict(color='blue', width=2)), row=1, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_bur['Date'], y = df_bur['daily_deaths'],name=' Daily Deaths',
                        line = dict(color='red', width=0.75)), row=1, col=4,secondary_y=True)
#Graph 5
fig.add_trace(go.Scatter(x = df_sin['Date'], y = df_sin['Deaths'],name='Total Deaths',
                        line = dict(color='blue', width=2)), row=1, col=5,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sin['Date'], y = df_sin['daily_deaths'],name=' Daily Deaths',
                        line = dict(color='red', width=0.75)), row=1, col=5,secondary_y=True)
#Row 2
#Graph 6
fig.add_trace(go.Scatter(x = df_tha['Date'], y = df_tha['Deaths'],name='Total Deaths',
                        line = dict(color='blue', width=2)), row=2, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_tha['Date'], y = df_tha['daily_deaths'],name=' Daily Deaths',
                        line = dict(color='red', width=0.75)), row=2, col=1,secondary_y=True)
#Graph 7
fig.add_trace(go.Scatter(x = df_vie['Date'], y = df_vie['Deaths'],name='Total Deaths',
                        line = dict(color='blue', width=2)), row=2, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_vie['Date'], y = df_vie['daily_deaths'],name=' Daily Deaths',
                        line = dict(color='red', width=0.75)), row=2, col=2,secondary_y=True)
#Graph 8
fig.add_trace(go.Scatter(x = df_cam['Date'], y = df_cam['Deaths'],name='Total Deaths',
                        line = dict(color='blue', width=2)), row=2, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_cam['Date'], y = df_cam['daily_deaths'],name=' Daily Deaths',
                        line = dict(color='red', width=0.75)), row=2, col=3,secondary_y=True)
#Graph 9
fig.add_trace(go.Scatter(x = df_bru['Date'], y = df_bru['Deaths'],name='Total Deaths',
                        line = dict(color='blue', width=2)), row=2, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_bru['Date'], y = df_bru['daily_deaths'],name=' Daily Deaths',
                        line = dict(color='red', width=0.75)), row=2, col=4,secondary_y=True)
#Graph 10
fig.add_trace(go.Scatter(x = df_lao['Date'], y = df_lao['Deaths'],name='Total Deaths',
                        line = dict(color='blue', width=2)), row=2, col=5,secondary_y=False)
fig.add_trace(go.Scatter(x = df_lao['Date'], y = df_lao['daily_deaths'],name=' Daily Deaths',
                        line = dict(color='red', width=0.75)), row=2, col=5,secondary_y=True)

#Adding title and adjusting the layout
fig.update_layout(height=500,showlegend=False,title_text="Covid19 Total Deaths And Daily Cases At ASEAN Countries",title_x=0.5)
fig.update_annotations(font=dict(family="Helvetica", size=10))
fig.update_layout(font=dict(family="Helvetica", size=12))
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
#Plotting the graph
fig.show()
In [47]:
dfworld3 = dfworld2.sort_values('Total Cases',ascending=False).head(10)

def highlight_max(s):
    '''
    highlight the maximum in a Series Salmon.
    '''
    is_max = s == s.max()
    return ['background-color: salmon' if v else '' for v in is_max]

dfworld3.style.set_caption("Overview Of Top 10 Highest Covid19 Cases Worldwide").set_table_styles([{
    'selector': 'caption',
    'props': [
        ('color', 'black'),
        ('font-size', '26px'),
        ("text-align", "center"),
        ('text-decoration', 'underline'),
        ('font-family','Arial'),
        ('text-shadow', '2px 2px 5px grey')
    ]},(dict
        (selector='th',props=[('text-align',
                               'left')]))]).format(
    {'Total Cases':'{:,.0f}','Total Deaths':'{:,.0f}','People Vaccinated':'{:,.0f}','Population':'{:,.0f}',
     'Population Density':'{:,.1f}','GDP Per Kapita':'{:,.1f}','Cases (%)':'{:,.1f}','Deaths (%)':'{:,.1f}',
     'Vaccination (%)':'{:,.1f}'}).set_properties(subset=['Country'],**{'text-align': 'left'}).hide_index().apply(
    highlight_max,subset=['Total Cases','Total Deaths','People Vaccinated','Population','Population Density',
                          'GDP Per Kapita','Cases (%)','Deaths (%)','Vaccination (%)'])
Out[47]:
Overview Of Top 10 Highest Covid19 Cases Worldwide
Country Total Cases Total Deaths People Vaccinated Population Population Density GDP Per Kapita Cases (%) Deaths (%) Vaccination (%)
United States 77,707,349 919,255 251,926,344 332,915,074 35.6 54,225.4 23.3 1.2 75.7
India 42,631,421 508,665 957,047,881 1,393,409,033 450.4 6,426.7 3.1 1.2 68.7
Brazil 27,434,286 638,346 174,117,725 213,993,441 25.0 14,103.5 12.8 2.3 81.4
France 21,674,802 134,766 53,879,448 67,422,000 122.6 38,605.7 32.1 0.6 79.9
United Kingdom 18,312,381 159,655 52,491,142 68,207,114 272.9 39,753.2 26.8 0.9 77.0
Russia 13,728,138 332,727 77,847,010 145,912,022 8.8 24,766.0 9.4 2.4 53.4
Turkey 12,834,534 90,266 57,559,910 85,042,736 104.9 25,129.3 15.1 0.7 67.7
Germany 12,391,463 119,939 63,274,587 83,900,471 237.0 45,229.2 14.8 1.0 75.4
Italy 12,053,330 150,824 50,502,243 60,367,471 205.9 35,220.1 20.0 1.3 83.7
Spain 10,604,200 95,995 40,986,943 46,745,211 93.1 34,272.4 22.7 0.9 87.7
In [48]:
dfworld3 = dfworld2.sort_values('People Vaccinated',ascending=False).head(10)

def highlight_max(s):
    '''
    highlight the maximum in a Series Salmon.
    '''
    is_max = s == s.max()
    return ['background-color: salmon' if v else '' for v in is_max]

dfworld3.style.set_caption("Overview Of Top 10 Highest Covid19 People Vaccinated Worldwide").set_table_styles([{
    'selector': 'caption',
    'props': [
        ('color', 'black'),
        ('font-size', '26px'),
        ("text-align", "center"),
        ('text-decoration', 'underline'),
        ('font-family','Arial'),
        ('text-shadow', '2px 2px 5px grey')
    ]},(dict
        (selector='th',props=[('text-align',
                               'left')]))]).format(
    {'Total Cases':'{:,.0f}','Total Deaths':'{:,.0f}','People Vaccinated':'{:,.0f}','Population':'{:,.0f}',
     'Population Density':'{:,.1f}','GDP Per Kapita':'{:,.1f}','Cases (%)':'{:,.1f}','Deaths (%)':'{:,.1f}',
     'Vaccination (%)':'{:,.1f}'}).set_properties(subset=['Country'],**{'text-align': 'left'}).hide_index().apply(
    highlight_max,subset=['Total Cases','Total Deaths','People Vaccinated','Population','Population Density',
                          'GDP Per Kapita','Cases (%)','Deaths (%)','Vaccination (%)'])
Out[48]:
Overview Of Top 10 Highest Covid19 People Vaccinated Worldwide
Country Total Cases Total Deaths People Vaccinated Population Population Density GDP Per Kapita Cases (%) Deaths (%) Vaccination (%)
China 106,930 4,636 1,266,426,000 1,444,216,102 147.7 15,308.7 0.0 4.3 87.7
India 42,631,421 508,665 957,047,881 1,393,409,033 450.4 6,426.7 3.1 1.2 68.7
United States 77,707,349 919,255 251,926,344 332,915,074 35.6 54,225.4 23.3 1.2 75.7
Indonesia 4,763,252 145,065 188,060,706 276,361,788 145.7 11,188.7 1.7 3.0 68.0
Brazil 27,434,286 638,346 174,117,725 213,993,441 25.0 14,103.5 12.8 2.3 81.4
Pakistan 1,483,798 29,772 115,238,268 225,199,929 255.6 5,034.7 0.7 2.0 51.2
Japan 3,842,551 20,234 101,480,129 126,050,796 347.8 39,002.2 3.0 0.5 80.5
Mexico 5,283,852 312,697 84,064,526 130,262,220 66.4 17,336.5 4.1 5.9 64.5
Vietnam 2,484,481 38,862 79,162,150 98,168,829 308.1 6,171.9 2.5 1.6 80.6
Russia 13,728,138 332,727 77,847,010 145,912,022 8.8 24,766.0 9.4 2.4 53.4
In [49]:
dfworld3 = dfworld2.sort_values('Population',ascending=False).head(10)

def highlight_max(s):
    '''
    highlight the maximum in a Series Salmon.
    '''
    is_max = s == s.max()
    return ['background-color: salmon' if v else '' for v in is_max]

dfworld3.style.set_caption("Overview Of Top 10 Highest Population Countries Worldwide").set_table_styles([{
    'selector': 'caption',
    'props': [
        ('color', 'black'),
        ('font-size', '26px'),
        ("text-align", "center"),
        ('text-decoration', 'underline'),
        ('font-family','Arial'),
        ('text-shadow', '2px 2px 5px grey')
    ]},(dict
        (selector='th',props=[('text-align',
                               'left')]))]).format(
    {'Total Cases':'{:,.0f}','Total Deaths':'{:,.0f}','People Vaccinated':'{:,.0f}','Population':'{:,.0f}',
     'Population Density':'{:,.1f}','GDP Per Kapita':'{:,.1f}','Cases (%)':'{:,.1f}','Deaths (%)':'{:,.1f}',
     'Vaccination (%)':'{:,.1f}'}).set_properties(subset=['Country'],**{'text-align': 'left'}).hide_index().apply(
    highlight_max,subset=['Total Cases','Total Deaths','People Vaccinated','Population','Population Density',
                          'GDP Per Kapita','Cases (%)','Deaths (%)','Vaccination (%)'])
Out[49]:
Overview Of Top 10 Highest Population Countries Worldwide
Country Total Cases Total Deaths People Vaccinated Population Population Density GDP Per Kapita Cases (%) Deaths (%) Vaccination (%)
China 106,930 4,636 1,266,426,000 1,444,216,102 147.7 15,308.7 0.0 4.3 87.7
India 42,631,421 508,665 957,047,881 1,393,409,033 450.4 6,426.7 3.1 1.2 68.7
United States 77,707,349 919,255 251,926,344 332,915,074 35.6 54,225.4 23.3 1.2 75.7
Indonesia 4,763,252 145,065 188,060,706 276,361,788 145.7 11,188.7 1.7 3.0 68.0
Pakistan 1,483,798 29,772 115,238,268 225,199,929 255.6 5,034.7 0.7 2.0 51.2
Brazil 27,434,286 638,346 174,117,725 213,993,441 25.0 14,103.5 12.8 2.3 81.4
Nigeria 253,978 3,141 nan 211,400,704 209.6 5,338.5 0.1 1.2 nan
Bangladesh 1,904,826 28,791 nan 166,303,494 1,265.0 3,524.0 1.1 1.5 nan
Russia 13,728,138 332,727 77,847,010 145,912,022 8.8 24,766.0 9.4 2.4 53.4
Mexico 5,283,852 312,697 84,064,526 130,262,220 66.4 17,336.5 4.1 5.9 64.5

End Of Report